#import <Cocoa/Cocoa.h>
#import "ManagingViewController.h"
#import "RNSearch.h"

@class RNStore;
@class RNSourceList;
@class RNDetailView;
@class RNEditListItemViewController;
@class RNEditItemViewController;
@class RNEditViewController;
@class RNFilteringArrayController;
@class RNSegmentedControl;

@interface DetailViewController : ManagingViewController <NSOutlineViewDataSource> {
    IBOutlet RNDetailView *detailView_;
    IBOutlet NSScrollView *detailScrollView_;
    NSTreeController *detailViewController_;
    BOOL expandGroups_;
    NSArray *currentDetailHeaders_;
    NSMutableDictionary *detailCells_;
    NSArray *titleAndIndexSortDescriptors_;
    NSArray *loggedDateSortDescriptors_;
    NSArray *currentSortDescriptors_;
    
    RNEditListItemViewController *editListItemViewController_;
    RNEditItemViewController *editItemViewController_;
    RNEditViewController *editViewController_;
    
    RNStore *storeFilter_;
    
    // Change category sheet
    NSWindow *changeCategorySheet_;
    NSTextField *changeCategoryTitleField_;
    NSBrowser *changeCategoryBrowser_;
    NSArray *categoriesControllerSortDescriptors_;
    NSArray *itemsToChange_;
    NSArray *titleDescriptor_;
	NSArray *aisleNumberDescriptor_;
    NSString *sheetTitle_;

    // Change aisle sheet
    NSWindow *changeAisleSheet_;
    NSTextField *changeAisleTitleField_;
    NSArrayController *aislesController_;
    NSArrayController *storesController_;
    
    // Add list item sheet
    NSWindow *addListItemSheet_;
    NSSearchField *addListItemSearchField_;
    RNFilteringArrayController *filteredItemsController_;
    NSTextField *addListItemTitleField_;
    NSTextField *searchResultsField_;
    NSTableView *searchResultsTable_;
    RNSegmentedControl *addAndRepeatButton_;
    NSButton *cancelAddListItemButton_;
    NSArray *addListItemControllerDescriptors_;
    
    // Print view
    NSView *printView_;
    NSOutlineView *printDetailView_;
    NSScrollView *printDetailScrollView_;
    NSTextField *titleField_;
    
    // Application search
    NSSearchField *applicationSearchField_;
    RNSearchType cachedSearchType_;
    
    // Detail Guide Views
    NSView *currentDetailGuideView_;
    NSView *emptyListGuide_;
    NSView *favoritesGuide_;
    NSView *historyGuide_;
    NSView *storeGuide_;
}

@property (nonatomic, readonly) RNDetailView *detailView;
@property (nonatomic, readonly) NSScrollView *detailScrollView;
@property (nonatomic, assign) BOOL expandGroups;
@property (nonatomic, retain) NSArray *currentDetailHeaders;
@property (nonatomic, readonly) NSMutableDictionary *detailCells;
@property (nonatomic, retain) RNEditListItemViewController *editListItemViewController;
@property (nonatomic, retain) RNEditItemViewController *editItemViewController;
@property (nonatomic, retain) RNEditViewController *editViewController;
@property (nonatomic, retain) RNStore *storeFilter;
@property (nonatomic, assign) IBOutlet NSTreeController *detailTreeController;
@property (nonatomic, retain) NSArray *aisleNumberDescriptor;
@property (nonatomic, retain) NSArray *titleDescriptor;
@property (nonatomic, retain) NSArray *titleAndIndexSortDescriptors;
@property (nonatomic, retain) NSArray *loggedDateSortDescriptors;
@property (nonatomic, retain) NSArray *currentSortDescriptors;
@property (nonatomic, retain) id rootObject;

-(void)editItemViewDidHide:(NSNotification *)notification;

-(void)showEditItemViewAtRow:(NSInteger)rowIndex;
-(void)reloadDetailView;
-(IBAction)toggleComplete:(id)sender;
-(IBAction)deleteSelectedItems:(id)sender;
-(IBAction)editSelectedItem:(id)sender;
-(IBAction)swapShowsChildrenAndReload:(id)sender;
-(IBAction)resetStoreFilter:(id)sender;
-(IBAction)clearCompletedItems:(id)sender;
-(IBAction)incrementCount:(id)sender;
-(IBAction)decrementCount:(id)sender;
-(void)clearCompletedItemsInAllLists;
-(IBAction)openContainer:(id)sender;
-(NSString *)buildSheetTitleFromArray:(NSArray *)arrayOfTitles;

#pragma mark -
#pragma mark Change category sheet
@property (assign) IBOutlet NSWindow *changeCategorySheet;
@property (assign) IBOutlet NSTextField *changeCategoryTitleField;
@property (assign) IBOutlet NSBrowser *changeCategoryBrowser;
@property (retain) NSArray *categoriesControllerSortDescriptors;
@property (copy) NSString *sheetTitle;
@property (retain) NSArray *itemsToChange;


#pragma mark -
#pragma mark Change aisle sheet
@property (assign) IBOutlet NSWindow *changeAisleSheet;
@property (assign) IBOutlet NSTextField *changeAisleTitleField;
@property (assign) IBOutlet NSArrayController *aislesController;
@property (assign) IBOutlet NSArrayController *storesController;


#pragma mark -
#pragma mark Add list item sheet
@property (nonatomic, assign) IBOutlet NSSearchField *addListItemSearchField;
@property (nonatomic, assign) IBOutlet RNFilteringArrayController *filteredItemsArrayController;
@property (nonatomic, assign) IBOutlet NSTextField *addListItemTitleField;
@property (nonatomic, assign) IBOutlet NSWindow *addListItemSheet;
@property (nonatomic, assign) IBOutlet NSTextField *searchResultsField;
@property (nonatomic, assign) IBOutlet NSTableView *searchResultsTable;
@property (nonatomic, assign) IBOutlet RNSegmentedControl *addAndRepeatButton;
@property (nonatomic, assign) IBOutlet NSButton *cancelAddListItemButton;
@property (nonatomic, readonly) NSArray *addListItemControllerDescriptors;


#pragma mark -
#pragma mark Application search
@property (nonatomic, assign) IBOutlet NSSearchField *applicationSearchField;
@property (nonatomic, assign) RNSearchType cachedSearchType;
-(IBAction)setSearchType:(id)sender;
-(IBAction)applicationSearchStringChanged:(id)sender;

- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item;


#pragma mark -
#pragma mark Print
@property (nonatomic, assign) IBOutlet NSView *printView;
@property (nonatomic, assign) IBOutlet NSOutlineView *printDetailView;
@property (nonatomic, assign) IBOutlet NSTextField *titleField;
@property (nonatomic, assign) IBOutlet NSScrollView *printDetailScrollView;

#pragma mark -
#pragma mark Detail Guide Views
@property (nonatomic, retain) NSView *currentDetailGuideView;
@property (nonatomic, retain) IBOutlet NSView *emptyListGuide;
@property (nonatomic, retain) IBOutlet NSView *favoritesGuide;
@property (nonatomic, retain) IBOutlet NSView *historyGuide;
@property (nonatomic, retain) IBOutlet NSView *storeGuide;

@end
